/*
 * RandomSeed.hpp
 *
 *  Created on: 2011-7-22
 *      Author: Administrator
 */

#ifndef RANDOMSEED_HPP_
#define RANDOMSEED_HPP_

#include <timer.h>
#include <sys/time.h>
#include <fcntl.h>
#include <unistd.h>


class RandomSeed
{
public:
	RandomSeed();
	virtual ~RandomSeed();

 static long generate(){
	 unsigned long ticks;
	 struct timeval tv;
	 int fd;
	 gettimeofday(&tv, NULL);
	 ticks = tv.tv_sec * 1000000 + tv.tv_usec;
	 fd = open("/dev/urandom", O_RDONLY );

	 if(fd > 0){
		 unsigned int r;
		 for(int i=0;i<512;i++){
			 read(fd, &r, sizeof(r));
			 ticks += r;
		 }
	 }
	 close(fd);
	 return ticks;
 }
};

#endif /* RANDOMSEED_HPP_ */
